package com.itheima.tliaswebmanagement.service.impl;

import com.itheima.tliaswebmanagement.mapper.EmpMapper;
import com.itheima.tliaswebmanagement.mapper.StudentMapper;
import com.itheima.tliaswebmanagement.pojo.CountDateOption;
import com.itheima.tliaswebmanagement.pojo.DegreeDataOption;
import com.itheima.tliaswebmanagement.pojo.JobDataOption;
import com.itheima.tliaswebmanagement.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public JobDataOption getEmpJobData() {
        List<Map<String, Object>> list = empMapper.countJobData();
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> datalList = list.stream().map(dataMap -> dataMap.get("total")).toList();
        return new JobDataOption(jobList, datalList);
    }

    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.countGenderData() ;
    }

    @Override
    public CountDateOption getStudentCountData() {
        List<Map<String, Object>> list= studentMapper.countCountData();
        List<Object> classList = list.stream().map(e -> e.get("class")).toList();
        List<Object> countList = list.stream().map(e -> e.get("count")).toList();
        return new CountDateOption(classList, countList);
    }

    @Override
    public DegreeDataOption getStudentDegreeData() {
        List<Map<String, Object>> list= studentMapper.countDegreeData();
        List<Object> classList = list.stream().map(e -> e.get("degree")).toList();
        List<Object> countList = list.stream().map(e -> e.get("count")).toList();
        return new DegreeDataOption(classList, countList);
    }
}
